package cn.javazd.demo;

import org.apache.commons.lang3.StringUtils;


public class SeqTest {
	
	public static void main(String[] args) {
		/*// 补位字符
		String str = "";
		// 设置补位长度
		for (int i = 0; i < 7; i++) {
			str += "0";
		}
		System.out.println("补位字符: " + str);
		// JAVA补字符串固定位数自增，位数不够左补0操作
		for (int i = 0; i < 10; i++) {
			DecimalFormat countFormat = new DecimalFormat(str);
			System.out.println("Seq: 004" + countFormat.format(i + 1));
			System.out.println("Seq: 004" + StringUtils.leftPad(String.valueOf(i), 7, "0"));
		}

		
		String code = "7500";
		if(code.length() < 10) {
			code = StringUtils.leftPad(code, 10, "0");
		}
		System.out.println(code);*/
		try {
			Thread t1 = new Thread(new TestThread()); t1.start();
			Thread t2 = new Thread(new TestThread()); t2.start();
			Thread t3 = new Thread(new TestThread()); t3.start();
			Thread t4 = new Thread(new TestThread()); t4.start();
			Thread t5 = new Thread(new TestThread()); t5.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
}

class TestThread implements Runnable {
	
	private static Integer value = 0;
	private static Integer incrementNo = 1;

	public static synchronized String generateSeq() {
		System.out.print(Thread.currentThread().getName() + ":\t");
		value = value + incrementNo;
		return "004" + StringUtils.leftPad(String.valueOf(value), 7, "0");
	}

	@Override
	public void run() {
		System.out.println(generateSeq());
	}
}
